<?php


namespace app\controller\Web;

use app\service\Web\ProductService;
use support\Request;
use Throwable;
use app\util\ResponseTrait;

use hg\apidoc\annotation as Apidoc;

/**
 * @Apidoc\Title("产品")
 */
class ProductController
{
    use ResponseTrait;

    /**
     * @Apidoc\Url("/web/product/getList")
     * @Apidoc\Title("列表")
     * @Apidoc\Method("GET")
     * @Apidoc\Query(ref="pagingParam")
     * @Apidoc\Query("lang",type="string",require=false,default="",desc="语言类型【需写接口】")
     * @Apidoc\Query("product_cate_id",type="int",require=false,default="",desc="产品分类ID")
     * @Apidoc\Query("platform",type="string",require=false,default="",desc="平台类型【需写接口】")
     * @Apidoc\Returned(ref="pagingResponse")
     * @Apidoc\Returned("list",type="array", require=false, default="[]",desc="产品列表",table="product")
     */
    public function getList(Request $request){
        try {
            $where = [];
            $page = parameterCheck($request->input('page'), 'int', 1);
            $pageSize = parameterCheck($request->input('pageSize'), 'int', 10);

            $where['is_show'] = 10;
            $where['lang'] = parameterCheck($request->input('lang'), 'string', '');
            $where['product_cate_id'] = parameterCheck($request->input('product_cate_id'), 'float', 0);
            $where['platform'] = parameterCheck($request->input('platform'), 'string', '');

            $data = ProductService::getList($where, $page, $pageSize);

            return $this->success($data);
        } catch (Throwable $e) {
            return $this->fail($e);
        }
    }

    /**
     * @Apidoc\Url("/web/product/getInfo")
     * @Apidoc\Title("详情")
     * @Apidoc\Method("GET")
     * @Apidoc\Query("id",type="int",require=true,default="1",desc="产品ID")
     * @Apidoc\Returned(type="object", table="news")
     */
    public function getInfo(Request $request)
    {
        try {
            $where = [];

            $where['id'] = parameterCheck($request->input('id'), 'int', 0);

            $data = ProductService::getOne($where['id']);

            return $this->success($data);
        } catch (Throwable $e) {
            return $this->fail($e);
        }
    }
}